/*
 * @Author: Sam
 * @Date: 2020-10-12 15:23:33
 * @LastEditTime: 2021-04-07 14:19:10
 * @LastEditors: Sam
 * @Description: 
 * @FilePath: \resourcesf:\thework\tofba-client\src\store\modules\app.js
 * @可以输入预定的版权声明、个性签名、空行等
 */
import Cookies from 'js-cookie'
import { getLanguage } from '@/lang/index'
const state = {
  sidebar: {
    opened: false,
    withoutAnimation: false
  },
  device: 'desktop',
  language: getLanguage(),
  showPasswordDialog: false,
  loading: false
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', 1)
    } else {
      Cookies.set('sidebarStatus', 0)
    }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    Cookies.set('sidebarStatus', 0)
    state.sidebar.opened = false
    state.sidebar.withoutAnimation = withoutAnimation
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device
  },
  SET_LANGUAGE: (state, language) => {
    state.language = language
    Cookies.set('language', language)
  },
  TOGGLE_PASSWORD_DIALOG: state => {
    state.showPasswordDialog = !state.showPasswordDialog
  },
  TOGGLE_DIALOG: (state, status) => {
    state.loading = status

  }
}

const actions = {
  toggleSideBar ({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  closeSideBar ({ commit }, { withoutAnimation }) {
    commit('CLOSE_SIDEBAR', withoutAnimation)
  },
  toggleDevice ({ commit }, device) {
    commit('TOGGLE_DEVICE', device)
  },
  setLanguage ({ commit }, language) {
    commit('SET_LANGUAGE', language)
  },
  togglePasswordDialog ({ commit }) {
    commit('TOGGLE_PASSWORD_DIALOG')
  },
  toggleDialog ({ commit }, status) {
    commit('TOGGLE_DIALOG', status)
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
